using System;
using System.Collections;
using System.Collections.Generic;

namespace Me.Prettyprint.Cassandra.Service
{
	public class FailoverPolicy
	{
        public static FailoverPolicy FAIL_FAST = new FailoverPolicy(0, 0);
        public static FailoverPolicy ON_FAIL_TRY_ONE_NEXT_AVAILABLE = new FailoverPolicy(1, 0);
        public static FailoverPolicy ON_FAIL_TRY_ALL_AVAILABLE = new FailoverPolicy(int.MaxValue - 1, 0);

        public readonly int SleepBetweenHostsMS;
        protected List<Type> dontRetry;
        
        public FailoverPolicy(int numOfRetries, int sleepBwHostsMilli)
        {
            NumRetries = numOfRetries;
            this.SleepBetweenHostsMS = sleepBwHostsMilli;
        }
        public FailoverPolicy(int numOfRetries, int sleepBwHostsMilli, List<Type> dontRetryForTypes)
        {
            NumRetries = numOfRetries;
            this.SleepBetweenHostsMS = sleepBwHostsMilli;
            this.dontRetry = dontRetryForTypes;
        }
        public bool ShouldRetryFor(Type candidate)
        {
            if (dontRetry != null)
            {
                return !dontRetry.Contains(candidate);
            }
            else
            {
                return true;
            }
        }
        public int GetSleepBetweenHostsMS()
        {
            return this.SleepBetweenHostsMS;
        }
        public int NumRetries
        {
            get;
            protected set;
        }
    }
}